<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>wangEditor demo</title>
		<script src="plugins/Echart/echarts.min.js"></script>
		<script src="layui.all.js"></script>
		<script src="js/utils/common.js"></script>
	</head>
	<body>
		<div id="main" style="width: 1000px;height:400px;"></div>


		<script type="text/javascript">
			var $ = layui.jquery

			// 基于准备好的dom，初始化echarts实例
			var myChart = echarts.init(document.getElementById('main'), 'light');
			// 指定图表的配置项和数据
			myChart.setOption({
				grid: {
					left: 50,
					right: '0%',
					height: '50%',
					buttom: 0,
				},

				title: {
					text: '各手机品牌销量'
				},
				tooltip: {},
				legend: {
					data: ['销量', '金额'],

				},
				xAxis: {
					data: []
				},
				yAxis: {},
				series: [{
						name: '金额',
						type: 'bar',
						color: '#37a2da',
						data: []
					},
					{
						name: '销量',
						type: 'bar',
						color: '#ff0000',
						data: []
					}
				]
			});

			// 填入数据
			$.ajax({
				type: "POST",
				url: GlobalSiteUrl + "/admin/selectSaleAndIncome",
				// data: null,
				// dataType: 'json',
				success: function(result) {
					var mobileBrandArr = [];
					var money = [];
					var saleNumber = [];
					for (var i in result.data) {
						mobileBrandArr.push(result.data[i].mobileBrand)
						if (result.data[i].totalMoney == null) {
							money.push(0)
						} else {
							money.push(result.data[i].totalMoney)
						}

						saleNumber.push(result.data[i].number)
					}
					console.log(mobileBrandArr)
					console.log(money)
					console.log(saleNumber)
					myChart.setOption({
						xAxis: {
							data: mobileBrandArr
						},
						series: [{
							// 根据名字对应到相应的系列
							name: '金额',
							data: money
						}, {
							// 根据名字对应到相应的系列
							name: '销量',
							data: saleNumber
						}]
					});
				},
			});
		</script>


	</body>
</html>
